﻿using Logistics.And;
using Microsoft.AspNetCore.Http;
using Microsoft.AspNetCore.Mvc;
using System.Threading.Tasks;

namespace Logistics.Web.Controllers
{
    public class GatheringController : Controller
    {
        private readonly GatheringAppService _GatheringAppService;
        public GatheringController(GatheringAppService gatheringAppService)
        {
            _GatheringAppService = gatheringAppService;
        }
        /// <summary>
        /// 删除
        /// </summary>
        /// <param name="id"></param>
        /// <returns></returns>
        public Task DeleteAsyncc(int id)
        {
            var i = _GatheringAppService.DeleteAsync(id);
            return i;
        }
        /// <summary>
        /// 查看视图
        /// </summary>
        /// <returns></returns>
        public ActionResult GetGatheringIndex(int id)
        {
            ViewBag.Id = id;
            return View();
        }
        /// <summary>
        /// 反填视图
        /// </summary>
        /// <param name="id"></param>
        /// <returns></returns>
        public ActionResult PutGatheringIndex(int id)
        {
            ViewBag.Id = id;
            return View();
        }
        public IActionResult Updates(GatheringDto gathering)
        {
            var procur = _GatheringAppService.UpdateAsync(gathering);
            return Ok(procur);
        }

        /// <summary>
        /// 查看详情/反填
        /// </summary>
        /// <param name="id"></param>
        /// <returns></returns>
        public Task<GatheringDto> GetAsyncc(int id)
        {
            var Procur = _GatheringAppService.GetAsync(id);
            return Procur;
        }
        /// <summary>
        /// 添加视图
        /// </summary>
        /// <returns></returns>
        public ActionResult PostGatheringIndex()
        {
            return View();
        }
        /// <summary>
        /// 添加
        /// </summary>
        /// <param name="Procurement"></param>
        /// <returns></returns>
        public IActionResult Add(GatheringDto gathering)
        {
            var i = _GatheringAppService.CreateAsync(gathering).Result;
            return Ok(i);
        }
        /// <summary>
        /// 主页显示
        /// </summary>
        /// <returns></returns>
        public ActionResult GatheringIndex()
        {
            return View();
        }
        // GET: ApproveController/Details/5
        public JsonResult ShowGathering(GetGatheringListDto getGatheringListDto)
        {
            var Procurements = _GatheringAppService.GetListAsync(getGatheringListDto).Result;
            return Json(new { data = Procurements.Items, count = Procurements.TotalCount, code = "0", msg = "" });
        }
    }
}
